﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using The_Chronicles_of_Asku.Characters.Mobs.Bosses.Endgame_1;
using The_Chronicles_of_Asku.Areas.End_Game_Floors.Forest._1_5.Resources;
using The_Chronicles_of_Asku.Characters;
using The_Chronicles_of_Asku.Characters.Mobs;

namespace The_Chronicles_of_Asku.Areas.End_Game_Floors.Forest._1_5
{
    class AreaThree
    {
        Battle battle = new Battle();
        Skeleton skel = new Skeleton();
        Necromancer necro = new Necromancer();
        Undead zombie = new Undead();
        SetMobLevels setLevel = new SetMobLevels();
        Hero myHero = new Hero();
        Villager villager = new Villager();
        Bandit bandit = new Bandit();
        public bool complete = false;

        public void theFloor(Hero myHero, Mob mob)
        {
            setLevel.setMobLevelFiftyTierNine(skel, necro, zombie, bandit);

            Console.WriteLine(AreaThreeText.Entrance);
            SkeletonFight(myHero, skel);
            NecromancerFight(myHero, necro);
            SkeletonFight(myHero, skel);
            NecromancerFight(myHero, necro);
            SkeletonFight(myHero, skel);
            NecromancerFight(myHero, necro);
            SkeletonFight(myHero, skel);
            SkeletonFight(myHero, skel);
            NecromancerFight(myHero, necro);
            SkeletonFight(myHero, skel);
            SkeletonFight(myHero, skel);
            SkeletonFight(myHero, skel);
            SkeletonFight(myHero, skel);


            if (myHero.isAlive == true)
            {
                Random rnd = new Random();
                int goldInChest = rnd.Next(100, 501);
                myHero.gold += goldInChest;
                if (myHero.gold >= myHero.goldCap)
                {
                    myHero.gold = myHero.goldCap;
                }
                int tempGold = myHero.gold;
                Console.WriteLine(AreaThreeText.ThingOne, goldInChest, myHero.gold);
                BanditFight(myHero, bandit);
                BanditFight(myHero, bandit);
                BanditFight(myHero, bandit);
                BanditFight(myHero, bandit);
                BanditFight(myHero, bandit);
                BanditFight(myHero, bandit);
                BanditFight(myHero, bandit);
                BanditFight(myHero, bandit);
                BanditFight(myHero, bandit);
            }

            if (myHero.isAlive == true)
            {
                string answer = "";

                do
                {
                    Console.WriteLine(AreaThreeText.ThingTwo);
                    answer = Console.ReadLine();

                    switch (answer)
                    {
                        case "1":
                            if (myHero.isAlive == true)
                            {
                                Random rnd = new Random();
                                int goldInChest = rnd.Next(100, 501);
                                myHero.gold += goldInChest;
                                if (myHero.gold >= myHero.goldCap)
                                {
                                    myHero.gold = myHero.goldCap;
                                }
                                int tempGold = myHero.gold;
                                Console.WriteLine(AreaThreeText.ThingTwoLeft, goldInChest.ToString(), tempGold.ToString());
                                ClearScreen();
                            }
                            break;

                        case "2":
                            Console.WriteLine(AreaThreeText.ThingTwoStraight);
                            UndeadFight(myHero, zombie);
                            UndeadFight(myHero, zombie);
                            UndeadFight(myHero, zombie);
                            UndeadFight(myHero, zombie);
                            UndeadFight(myHero, zombie);
                            break;

                        case "3":
                            Console.WriteLine(AreaThreeText.ThingTwoRight);
                            ClearScreen();
                            break; 

                        default:
                            Console.WriteLine("Invalid choice!");
                            ClearScreen();
                            break;
                    }
                } while (answer != "2" && myHero.isAlive == true);
            }


            if (myHero.isAlive == true)
            {
                Console.WriteLine(AreaThreeText.ThingThree);
                NecromancerFight(myHero, necro);
                NecromancerFight(myHero, necro);
                NecromancerFight(myHero, necro);
                NecromancerFight(myHero, necro);
                NecromancerFight(myHero, necro);
                NecromancerFight(myHero, necro);
                NecromancerFight(myHero, necro);
                NecromancerFight(myHero, necro);
                NecromancerFight(myHero, necro);
                NecromancerFight(myHero, necro);
            }

            if (myHero.isAlive == true)
            {
                Console.WriteLine(AreaThreeText.ThingFour);
                SkeletonFight(myHero, skel);
                SkeletonFight(myHero, skel);
                SkeletonFight(myHero, skel);
                SkeletonFight(myHero, skel);
                SkeletonFight(myHero, skel);
                SkeletonFight(myHero, skel);
                SkeletonFight(myHero, skel);
                SkeletonFight(myHero, skel);
                SkeletonFight(myHero, skel);
                SkeletonFight(myHero, skel);
                SkeletonFight(myHero, skel);
                SkeletonFight(myHero, skel);
                SkeletonFight(myHero, skel);
                SkeletonFight(myHero, skel);
                SkeletonFight(myHero, skel);
                SkeletonFight(myHero, skel);
            }

            if (myHero.isAlive == true)
            {
                string answer = "";

                do
                {
                    Console.WriteLine(AreaThreeText.ThingFive);
                    answer = Console.ReadLine();

                    switch (answer)
                    {
                        case "1":
                            Console.WriteLine(AreaThreeText.ThingFiveLeft);
                            UndeadFight(myHero, zombie);
                            UndeadFight(myHero, zombie);
                            UndeadFight(myHero, zombie);
                            UndeadFight(myHero, zombie);
                            UndeadFight(myHero, zombie);
                            UndeadFight(myHero, zombie);
                            UndeadFight(myHero, zombie);
                            UndeadFight(myHero, zombie);
                            UndeadFight(myHero, zombie);
                            break;

                        case "2":
                            Console.WriteLine(AreaThreeText.ThingFiveRight);
                            BanditFight(myHero, bandit);
                            BanditFight(myHero, bandit);
                            BanditFight(myHero, bandit);
                            BanditFight(myHero, bandit);
                            BanditFight(myHero, bandit);
                            BanditFight(myHero, bandit);
                            BanditFight(myHero, bandit);
                            break;

                        default:
                            Console.WriteLine("Invalid choice!");
                            ClearScreen();
                            break;
                    }
                } while (answer != "1" && answer != "2" && myHero.isAlive == true);
            }

            if (myHero.isAlive == true)
            {
                Console.WriteLine(AreaThreeText.ThingSix);
                NecromancerFight(myHero, necro);
                NecromancerFight(myHero, necro);
                NecromancerFight(myHero, necro);
                NecromancerFight(myHero, necro);
                NecromancerFight(myHero, necro);
                NecromancerFight(myHero, necro);
                NecromancerFight(myHero, necro);
            }

            if (myHero.isAlive == true)
            {
                Console.WriteLine(AreaThreeText.Exit);
                ClearScreen();
                complete = true;
            }


            if (myHero.isAlive == false)
            {
                Console.WriteLine(AreaThreeText.Dead);
                myHero.isAlive = true;
            }
        }

        private void UndeadFight(Hero myHero, Undead zombie)
        {
            if (myHero.isAlive == true)
            {
                battle.Fight(myHero, zombie);
                Console.ReadKey();
            }
            myHero.ResetStats(myHero);
            zombie.ResetStats(zombie);

            Console.Clear();
        }

        private void SkeletonFight(Hero myHero, Skeleton skel)
        {
            if (myHero.isAlive == true)
            {
                battle.Fight(myHero, skel);
                Console.ReadKey();
            }
            myHero.ResetStats(myHero);
            skel.ResetStats(skel);

            Console.Clear();
        }

        private void NecromancerFight(Hero myHero, Necromancer necro)
        {
            if (myHero.isAlive == true)
            {
                battle.Fight(myHero, necro);
                Console.ReadKey();
            }
            myHero.ResetStats(myHero);
            necro.ResetStats(necro);

            Console.Clear();
        }

        private void VillagerFight(Hero myHero, Villager villager)
        {
            if (myHero.isAlive == true)
            {
                battle.Fight(myHero, villager);
                Console.ReadKey();
            }
            myHero.ResetStats(myHero);
            villager.ResetStats(villager);

            Console.Clear();
        }

        private void BanditFight(Hero myHero, Bandit bandit)
        {
            if (myHero.isAlive == true)
            {
                battle.Fight(myHero, bandit);
                Console.ReadKey();
            }
            myHero.ResetStats(myHero);
            bandit.ResetStats(bandit);

            Console.Clear();
        }

        private void ClearScreen()
        {
            Console.ReadKey();
            Console.Clear();
        }
    }
}
